/**
 * @param {number[]} nums
 * @return {number}
 */
 var minimumOperations = function(nums) {
  const n = nums.length
  let ans = 0
  const mp1 = new Map(), mp2 = new Map()
  for(let i = 0; i<n; i+=2){
    mp1.set(nums[i], (mp1.get(nums[i]) ?? 0) + 1)
  }
  for(let i = 1; i<n; i+=2) {
    mp2.set(nums[i], (mp2.get(nums[i]) ?? 0) + 1)
  }
  let max1 = 0, maxCnt1 = 0
  for(let [x, cnt] of mp1) {
    if(cnt > maxCnt1){
      max1 = x
      maxCnt1 = cnt
    }
  }
  let max2 = 0, maxCnt2 = 0
  for(let [x, cnt] of mp2) {
    if(cnt > maxCnt2){
      max2 = x
      maxCnt2 = cnt
    }
  }
  if(max1 !== max2) {
    return n - maxCnt1 - maxCnt2
  }
  if(maxCnt1 > maxCnt2) {
    const arr = [...mp2.values()]
    if(arr.length === 1){
      return n - maxCnt1
    }
    let x = [...mp2.values()].sort((a,b) => b-a)[1]
    return n - x - maxCnt1
  } else {
    const arr = [...mp1.values()]
    if(arr.length === 1){
      return n - maxCnt2
    }
    let x = arr.sort((a,b) => b-a)[1]
    return n - x - maxCnt2
  }
};